/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.eclass.servlet.front;

import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;

import cn.eclass.bean.api.IUserBean;
import cn.eclass.entity.UserEntity;
import cn.eclass.servlet.ActionFace;
import cn.eclass.utils.BeanFactory;
import cn.eclass.utils.UserSessionInfo;

/**
 *
 * @author fortruth
 */
public class Uindex extends ActionFace {

	private void checkLogIn() throws ServletException, IOException {
		if(user != null) return;

		request.setAttribute("redirect", "uindex");
		request.getRequestDispatcher(logInView).forward(request, response);
	}
	
    @Override
    public void doIndex() {
        try {
        	checkLogIn();
        	UserSessionInfo usi = new UserSessionInfo(user, session);
        	usi.setGiftOrderList();
        	usi.setSchoolOrderList();
        	
//        	IUserBean userBean = BeanFactory.factory.getUserBean();
//        	String userName = (String) session.getAttribute("username");
//        	UserEntity user = userBean.getByName(userName);
//        	request.setAttribute("userEnt", user);
        	
        	DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.CHINESE); 
        	Date d = new Date(user.getLastLoginTime());
        	String time = df.format(d);
        	
        	request.setAttribute("lastLogin", time);
            request.getRequestDispatcher(view).forward(request, response);
        } catch (ServletException ex) {
            Logger.getLogger(Uindex.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Uindex.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
